<%@page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@include file="/commons/include/html_doctype.html"%>
<html>
<head>
<title>用户部门分配</title>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="${ctx}/js/tree/zTreeStyle/zTreeStyle.css" />
<style type="text/css">
/*文档*/
body{margin:0;width:100%;}
/*用户部门层*/
#div_userDept{margin:10px;}
/*用户部门表*/
#tb_userDept{width:100%;border-collapse:collapse;}
/*用户部门表列*/
#tb_userDept td{text-align:center;border:1px solid #6EA5EB;}
/*表、列标题行高*/
#tr_tb_title,#tr_col_title{height:30px;}
/*列标题行*/
#tr_col_title{background-color:#DFEFFF;}
/*所有用户、部门列*/
#td_allUser,#td_allDept{width:50%;}
/*用户、部门层*/
#div_user,#div_dept{width:100%;height:350px;margin:0;overflow:auto;}
/*用户表*/
#tb_user {width:100%;}
/*用户表行*/
#tr_user {background-color:#D4D0C8;}
/*部门树*/
#ul_dept{margin:0;padding:0;}
/*奇、偶、悬停行*/
.odd{background-color:#f7fbff;}.even{background-color:#ffffff;}.over{background-color:#fdfad0;}
</style>
<script type="text/javascript" src="${ctx }/js/jquery/jquery.js"></script>
<script type="text/javascript" src="${ctx }/js/tree/jquery-ztree.js"></script>
<script type="text/javascript" src="${ctx }/js/include/get.js"></script>
<script type="text/javascript">
$(function(){
	var _tree,_userid;
	//加载
	$.post("${ctx}/manage/sys/user/getUserJson.htm",function(data){
		$(eval(data)).each(function(i){
			$("#tb_user").append("<tr class='"+(0==i%2?"even":"odd")+"'><td><input id='"+this.id+"' name='user' type='radio' class='btn_assign' /input></td><td>"+this.name+"</td><td>"+this.account+"</td></tr>");
		});
		_highLight();$("#tb_user tr:first td").css("border-top","0");$("#tb_user td:first-child").css("border-left","0");$("#tb_user td:last-child").css("border-right","0");
		$(".btn_assign").click(function(){
			_userid=this.id;
			$.post("${ctx}/manage/sys/dept/getDeptOfUser.htm",{userid:this.id},function(data){
				_tree=$("#ul_dept").zTree({isSimpleData:true,treeNodeKey:"id",treeNodeParentKey:"pid",expandSpeed:"",checkable:true,checkStyle:"radio",checkRadioType:"all"},eval(data));
			});
		});
	});
	//按钮
	$("#td_btn>input[type='button']").each(function(){
		switch(this.id){
		case"btn_assign":
		$(this).click(function(){
			if(!_tree)return;
			var _node=_tree.getCheckedNodes();
			$.post("${ctx}/manage/sys/assignUserDept2.htm",{userid:_userid,deptid:(""==_node?"":_node[0].id)},function(data){
				1==data?alert("分配成功！"):alert("分配失败！");
			});
		});break;
		case"btn_reset":
		$(this).click(function(){
			if(!_tree)return;
			var _arr=_tree.getCheckedNodes();
			$(_arr).each(function(){
				this.checked=false;_tree.refresh();
			});
		});break;
		}
	});
});
</script>
</head>
<body>
<div id="div_userDept">
<table id="tb_userDept" cellpadding="0">
	<tr id="tr_tb_title"><td colspan="2">用户部门分配</td></tr>
	<tr id="tr_col_title">
		<td id="td_allUser">所有用户</td>
		<td id="td_allDept">所有部门</td>
	</tr>
	<tr>
		<td id="td_user">
			<div id="div_user">
			<table id="tb_user" cellpadding="0">
				<tr id="tr_user">
					<td>分配</td> 
					<td>姓名</td> 
					<td>账号</td>
				</tr>
			</table>
			</div>
		</td>
		<td id="td_dept">
			<div id="div_dept"><ul id="ul_dept" class="tree" /></div>
		</td>
	</tr> 
	<tr>
		<td id="td_btn" colspan="2">
			<input type="button" id="btn_assign" value="保存" />
			<input type="button" id="btn_reset" value="重填" />
		</td>
	</tr>
</table>
</div>
</body>
</html>
